using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

using Syncfusion.Windows.Forms.Diagram;
using Syncfusion.Windows.Forms.Diagram.Controls;

using StateMachine_Graphical_Editor.Forms;
using StateMachine_Graphical_Editor.Utils.Forms_RunTime_Managment;

using KLATencor.CommonApp.Infrastructure.StateMachine;

namespace StateMachine_Graphical_Editor.Shapes
{
    /// <summary>
    /// Provides graphicalrepresention of a state in another hierarchy branch than form's main state.
    /// <para>Needed when such a state has transition to the main state's substates</para>
    /// </summary>
    public class OuterState : Ellipse
    {
        #region Members:

        private StatesForm _form;

        #endregion

        #region C'tor:

        public OuterState(string stateName, StateMachine machine, StatesForm form)
            : base(0, 0, 30, 30)
        {
            _form = form;

            Name = stateName;
            LineStyle.LineColor = Color.Black;
            LineStyle.LineWidth = 1;
            FillStyle.Color = Color.White;

            Syncfusion.Windows.Forms.Diagram.Label label = new Syncfusion.Windows.Forms.Diagram.Label(this, Name);
            label.FontStyle.Bold = true;
            label.FontStyle.Family = "Arial";
            label.FontStyle.Size = 8;
            this.Labels.Add(label); //add the new one
        }

        #endregion

        #region OnTransitionOccured event handler:

        public void handleEventForOuterState(StateChangeEventArgs args)
        {
            FormsManager manager = FormsManager.getManager();
            if (!manager.isTopForm(_form))
                return;

            if (args.NewState != null && Name.Equals(args.NewState.Name))
            {
                if (args.NewState.Parent == null) //parent is machine (main form)
                {
                }
                IFormManagment toLoad =
                    args.NewState.Parent == null ?
                    new SubStatesForm() :
                    new SubStatesForm(args.NewState.Parent, args.NewState, DisplayModes.VIEW_MODE);

                SubStatesForm thisForm = _form as SubStatesForm;
                manager.changeForms(thisForm.MainState, args.NewState, args.Transition, toLoad);

            }
        }

        #endregion
    }

}
